package org.kordakus.shoot.model.util;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.swing.SwingWorker;

import org.apache.log4j.Logger;
import org.kordakus.shoot.model.ImageFile;

public class ImportWorker extends SwingWorker<List<ImageFile>, Void>
{

	private static final Logger	_logger	= Logger.getLogger(ImportWorker.class);

	private final List<File>	_files;

	public ImportWorker(List<File> files)
	{
		_files = files;
	}

	@Override
	protected List<ImageFile> doInBackground() throws Exception
	{
		List<ImageFile> images = new ArrayList<ImageFile>();
		try
		{
			for (int i = 0; i < _files.size(); i++)
			{
				images.add(new ImageFile(_files.get(i)));
				setProgress((int) ((double) i / (double) _files.size() * 100.0));
			}
			return images;
		} catch (IOException e)
		{
			_logger.error("Import file failed (" + e.getMessage() + ")");
			throw e;
		}
	}
}
